Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document non-guarantees for Hash #90995

Merged
merged 2 commits into from
Nov 27, 2021
Merged

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Nov 18, 2021

Dependence on endianness and type sizes was reported for enum discriminants in #74215 but it is a more general
issue since for example the default implementation of Hasher::write_usize uses native endianness.
Additionally the implementations of library types are occasionally changed as their internal fields
change or hashing gets optimized.

Question

Should this go on the module level documentation instead since it also concerns Hasher to some extent and not just Hash?

resolves #74215

Dependence on endianness and type sizes was reported for enum discriminants in rust-lang#74215 but it is a more general
issue since for example the default implementation of `Hasher::write_usize` uses native endianness.
Additionally the implementations of library types are occasionally changed as their internal fields
change or hashing gets optimized.
@the8472 the8472 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Nov 18, 2021
@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 18, 2021
Copy link
Member

@pierwill pierwill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

library/core/src/hash/mod.rs Outdated Show resolved Hide resolved
library/core/src/hash/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
@nbdd0121
Copy link
Contributor

A hasher that overrides all provided methods could provide a portable hash though, right? E.g. always use LE, and delegate write_[ui]size to write_[ui]64.

@the8472
Copy link
Member Author

the8472 commented Nov 24, 2021

That could cover some cases, but the Hash implementation itself could also be platform-dependent because the type itself is or perhaps because it turns a [usize; N] into &[u8] and pass that to the Hasher. So both Hash and Hasher need to be vetted for portability.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me. Between here and the module docs, this is the place I would think to look first.

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Nov 26, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 26, 2021

📌 Commit 53fc69f has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2021
@dtolnay dtolnay assigned dtolnay and unassigned yaahc Nov 26, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 27, 2021
Document non-guarantees for Hash

Dependence on endianness and type sizes was reported for enum discriminants in rust-lang#74215 but it is a more general
issue since for example the default implementation of `Hasher::write_usize` uses native endianness.
Additionally the implementations of library types are occasionally changed as their internal fields
change or hashing gets optimized.

## Question

Should this go on the module level documentation instead since it also concerns `Hasher` to some extent and not just `Hash`?

resolves rust-lang#74215
This was referenced Nov 27, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 27, 2021
…askrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#83791 (Weaken guarantee around advancing underlying iterators in zip)
 - rust-lang#90995 (Document non-guarantees for Hash)
 - rust-lang#91057 (Expand `available_parallelism` docs in anticipation of cgroup quota support)
 - rust-lang#91062 (rustdoc: Consolidate static-file replacement mechanism)
 - rust-lang#91208 (Account for incorrect `where T::Assoc = Ty` bound)
 - rust-lang#91266 (Use non-generic inner function for pointer formatting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 43279b2 into rust-lang:master Nov 27, 2021
@rustbot rustbot added this to the 1.59.0 milestone Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hash of Discriminant now produces different results across CPU architectures
8 participants